package com.example.mvptest;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class JokePresenter implements Contract.iPresenter {

    Contract.iView view;
    Contract.iModel model;

    public JokePresenter(Contract.iView view) {
        this.view = view;
        model=new JokeModel();
    }

    @Override
    public void getJoke(String page) {

        view.loading();
        model.getJoker(page)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<JokeBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(JokeBean bean) {

                        if (view != null) {
                            view.dissmissLoading();
                            view.success(bean);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        if (view != null) {
                            view.dissmissLoading();
                            view.failed(e.toString());
                        }
                    }

                    @Override
                    public void onComplete() {

                    }
                });

//————————————————
//        版权声明：本文为CSDN博主「GaoYyyy」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
//        原文链接：https://blog.csdn.net/GaoYiranBlog/java/article/details/81003815
    }
}
